﻿using System.ComponentModel;
using System.Linq;
using System.Web.Mvc;
using SportsStore.Domain.Abstract;
using SportsStore.WebUI.Models;

namespace SportsStore.WebUI.Controllers {

  public class ProductsController: Controller {

    private readonly IProductsRepository productsRepository;
    public int PageSize = 4;

    public ProductsController(IProductsRepository productsRepository) {
      this.productsRepository = productsRepository;
    }

    public ViewResult List([DefaultValue(1)] int page)
    {
        var productsToShow = productsRepository.Products;
        var viewModel = new ProductsListViewModel {
            Products = productsToShow.Skip((page-1)*PageSize).Take(PageSize).ToList(),
            PagingInfo = new PagingInfo {
                CurrentPage = page,
                ItemsPerPage = PageSize,
                TotalItems = productsToShow.Count()
            }
        };
        return View(viewModel);
    }
  }

}
